﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DomainDrive.Core.Interface;

namespace Esb.Domain.DomainObjects
{
    /// <summary>
    /// 服务领域对象
    /// </summary>
    public class ServiceDo : IAggregateRoot<int>
    {
        /// <summary>
        /// 主键
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 服务的应用号
        /// </summary>
        public int ApplicationId { get; set; }

        /// <summary>
        /// 服务路由，即服务接口名
        /// </summary>
        public string ServiceRouteName { get; set; }

        ///// <summary>
        ///// 服务地址，针对具体环境分别配置
        ///// </summary>
        //public string ServiceUrl { get; protected set; }

        public string ServiceDescription { get; set; }

        /// <summary>
        /// 协议，例如：http
        /// </summary>
        public string Protocol { get; set; }

        /// <summary>
        /// 平台
        /// </summary>
        public string Platform { get; set; }

        /// <summary>
        /// 架构
        /// </summary>
        public string Architecture { get; set; }

        /// <summary>
        /// 域名
        /// </summary>
        public string DomainName { get; set; }

        /// <summary>
        /// 环境，分别为开发、测试、生产、预发布
        /// </summary>
        public List<EnvironmentDo> Environments { get; set; }

        /// <summary>
        /// 消费者集合，ApplicationId集合，用来控制权限
        /// </summary>
        public List<string> Consumers { get; set; }

        /// <summary>
        /// 告警邮件
        /// </summary>
        public string AlertMail { get; set; }

        /// <summary>
        /// 告警间隔
        /// </summary>
        public int AlertInterval { get; set; }

        /// <summary>
        /// 告警阈值
        /// </summary>
        public int AlertThreshold { get; set; }

        /// <summary>
        /// 创建服务领域对象
        /// </summary>
        /// <param name="applicationId"></param>
        /// <param name="serviceRouteName"></param>
        /// <param name="protocol"></param>
        /// <param name="platform"></param>
        /// <param name="architecture"></param>
        /// <param name="domainName"></param>
        public ServiceDo(int applicationId, string serviceRouteName, string protocol, string platform, string architecture, string domainName)
        {
            this.ApplicationId = applicationId;
            this.ServiceRouteName = serviceRouteName;

            this.Environments = new List<EnvironmentDo>();
            this.Consumers = new List<string>();

            this.Platform = platform;
            this.Architecture = architecture;
            this.DomainName = domainName;
            this.Protocol = protocol;
        }

        /// <summary>
        /// 默认构造函数
        /// </summary>
        public ServiceDo()
        {

        }

        /// <summary>
        /// 修改服务领域信息
        /// </summary>
        /// <param name="updateService"></param>
        /// <returns></returns>
        public ServiceDo Update(ServiceDo updateService)
        {
            this.ApplicationId = updateService.ApplicationId;
            this.ServiceRouteName = updateService.ServiceRouteName;
            this.ServiceDescription = updateService.ServiceDescription;

            this.Architecture = updateService.Architecture;
            this.DomainName = updateService.DomainName;
            this.Platform = updateService.Platform;
            this.Protocol = updateService.Protocol;

            this.Environments = updateService.Environments;
            this.Consumers = updateService.Consumers;

            this.AlertMail = updateService.AlertMail;
            this.AlertInterval = updateService.AlertInterval;
            this.AlertThreshold = updateService.AlertThreshold;

            return this;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <returns></returns>
        public bool Delete()
        {
            return true;
        }
    }
}
